<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>title</title>
</head>
<body>
<%
	//Create a variable for the connection string.
	String connectionUrl = "jdbc:sqlserver://localhost:1433;"
			+ "databaseName=test";
	String dbname = "sa";
	String dbpassword =  "123456";
	// Declare the JDBC objects.
	Connection con = null;
	Statement stmt = null;
	ResultSet rs = null;

	try {
		// Establish the connection.
		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		con = DriverManager.getConnection(connectionUrl, dbname, dbpassword);

		// Create and execute an SQL statement that returns some data.
		String SQL = "SELECT TOP 10 * FROM users";
		stmt = con.createStatement();
		rs = stmt.executeQuery(SQL);

		out.println("<table>");
		// Iterate through the data in the result set and display it.
		while (rs.next()) {
			out.println("<tr>");
			out.println("<td>" + rs.getString(1) + " " + rs.getString(2) + "</td>");
			out.println("</tr>");
		}
		out.println("</table>");
	}

	// Handle any errors that may have occurred.
	catch (Exception e) {
		e.printStackTrace();
	}

	finally {
		if (rs != null)
			try {
				rs.close();
			} catch (Exception e) {
			}
		if (stmt != null)
			try {
				stmt.close();
			} catch (Exception e) {
			}
		if (con != null)
			try {
				con.close();
			} catch (Exception e) {
			}
	}
%>
</body>
</html>